import * as actionType from './constants.js';
import {
    reqshopCar
} from '../../../api/index.js'

// 从后端请求数据 res.data.data
export const getShopcarData = () => {
    return (dispatch) => {
        reqshopCar()
            .then((res) => {
                console.log(res,"-----------------");
                dispatch(changeShopcarData(res.data.data))
            })
            .catch((e) => {
                console.log('出错了');
            })
    }
}

export const changeShopcarData = (data) => {
    return {
        type: actionType.CHANGE_SHOPCARDATA,
        data: data
    }
}



export const changeLogo = (data) => {
    return (dispatch) => {
        dispatch({
            type: actionType.CHANGE_LOGO,
            data: data
        })
    }
}

export const less_num = (data) => {
    return (dispatch) => {
        dispatch({
            type: actionType.LESSEN_NUM,
            data: data
        })
    }
}

export const add_num = (data) => {
    return (dispatch) => {
        dispatch({
            type: actionType.ADD_NUM,
            data: data
        })
    }
}

export const change_num = (num,id) => {
    return (dispatch) => {
        dispatch({
            type: actionType.CHNANGE_NUM,
            data: {num,id}
        })
    }
}

export const select_all = (data) => {
    return (dispatch) => {
        dispatch({
            type: actionType.SELECT_ALL,
            data: data
        })
    }
}

// 从详情页去到购物车页
export const goToShopCar = (data) => {
    return (dispatch) => {
        dispatch({
            type: actionType.GOTOSHOPCAR,
            data: data
        })
    }
}


export const delete_btn = (data) => {
    return (dispatch) => {
        dispatch({
            type: actionType.DELETE,
            data: data
        })
    }
}
